package cn.pku.sirx.snad.uias.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.util.Assert;

import cn.pku.sirx.snad.ad.dao.impl.DaoImpl;
import cn.pku.sirx.snad.uias.dao.IHometownDao;
import cn.pku.sirx.snad.uias.model.entity.HomeTown;

/**
 * @author WangXiao
 */
public class HometownDaoImpl extends DaoImpl<HomeTown> implements IHometownDao {

	public HometownDaoImpl() {
		super(HomeTown.class);
	}

	@Override
	public HomeTown getByUserId(String userId) {
		Assert.notNull(userId);

		DetachedCriteria criteria = DetachedCriteria.forClass(HomeTown.class);
		criteria.add(Restrictions.eq("userId", userId));
		List<HomeTown> hometowns = get(criteria);
		return hometowns.isEmpty() ? null : hometowns.get(0);
	}

}
